<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

	<table class = "table">
		<tr>
			<td>网站名</td>
			<td>网址</td>
			<td>创建时间</td>
			<td>操作</td>
		</tr>
<c:forEach items="${linkPage.list }" var = "link">
		<tr>
			<td>${link.name }</td>
			<td>${link.url }</td>
			<td>
				<fmt:formatDate value="${link.created }" pattern="yyyy-MM-dd"/>
			</td>
			<td>
				<a href = "javascript:delOne(${link.id })"><button type="button" class="btn btn-warning">删除</button></a>
				<a href = "/admin/toUpdateLink?id=${link.id }"><button type="button" class="btn btn-primary">修改</button></a> 
			</td>
		</tr>
</c:forEach>
		<tr>
			
				<td colspan="5">
			   		<nav aria-label="...">
					  <ul class="pagination">
					    
					    <li class="page-item">
					      <a class="page-link" href="javascript:showLink(1)" >首页</a>
					    </li>
					    <c:forEach begin="1" end="${linkPage.pages}" var="page">
					    	<li class="page-item"><a class="page-link" href="javascript:showLink(${page})">${page}</a></li>
					    </c:forEach>
					    <li class="page-item">
					      <a class="page-link" href="javascript:showLink(${linkPage.pages})">尾页</a>
					    </li>
					  </ul>
					</nav>
			   </td>
		</tr>
	</table>
	<a href="/admin/toAddLink"><button type="button" class="btn btn-primary">添加链接</button></a>
		
<script type="text/javascript">

function showLink(page){
	
	$("#workContent").load("/admin/showLink?pageNum="+page)
}

function delOne(id){
	$.post("/admin/delete",{id:id},function(msg){
		
		if(msg.id == 0){
			alert("删除成功");
			location = "/admin/toShowAll";
		}else{
			alert("删除失败")
		}
		
	},"json")
	
}

</script>	
	
	